#include <iostream>
#include <time.h>
int f(int num,int target){
    if (num==1)return 0;
    return ((f(num-1,target)+target)%num);

}

int main(){
    double dur;
	clock_t start,end;
    int num,target;
    std::cin>>num>>target;
	start=clock();
    std::cout<<f(num,target)<<std::endl;
    end=clock();
	dur=(double) end-start;
	std::cout<<dur<<std::endl;
    return 0;
}